package com.atguigu.handler;

import com.atguigu.pojo.Movie;
import com.atguigu.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 琉
 * @create 2021-09-07 16:59
 */
@RestController
@RequestMapping("/ajax")
public class AjaxHandler {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    //异步请求普通类型
    @RequestMapping("/commonParameter")
    public Movie commonParameter(User user){
        logger.debug(user.toString());

        Movie movie = new Movie(12,"肖申克救赎",10d);

        return movie;
    }


    //1. 获取Json请求体类型的参数必须要封装到POJO对象或者是Map中
    //2. POJO参数或者Map参数的前面一定要加入RequestBody注解
    //3. 你的项目中一定要引入jackson的依赖(因为SpringMVC默认支持jackson)
    //获取Json请求体类型的请求参数和获取普通类型的参数不一样

    //异步请求类型json参数
    @RequestMapping("/jsonBodyParameter")
    public Movie jsonParameter(@RequestBody User user){
        logger.debug(user.toString());

        Movie movie = new Movie(1,"水浒传",50.0);
        return movie;
    }





}
